package com.example.securingserver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caiwl
 * @date 2020/5/12 11:27
 */
@RestController
public class HomeCtrl {
    @Autowired
    private UserDAO userDAO;

    @RequestMapping("/")
    public String home() {
        return "Hello World";
    }

    @RequestMapping("/user/login")
    public String login(String username, String password) {
        UserDetails userDetails = userDAO.findByUsernameAndPassword(username, password);
        if (userDetails == null) {
            return "username or password error";
        }
        String jws = JwtsUtil.compact(userDetails);
        return "login success: " + jws;
    }
}
